package com.tosh;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.InputStream;
import java.util.logging.Logger;

/**
 * User: arsentyev
 * Date: 03.08.12
 */
public class ApplicationListenerFastDI implements ServletContextListener {
    private final Logger _log = Logger.getLogger(getClass().getName());
    private static final String _configLocation = "ioc-configLocation";

    @Override
    public void contextInitialized(ServletContextEvent sev) {
        Object obj = sev.getServletContext().getInitParameter(_configLocation);
        if(obj == null) {
            _log.severe("No configuration file provided.");
            return;
        }
        InputStream is = sev.getServletContext().getResourceAsStream((String)obj);
        AppFastDI fastDI = new AppFastDI(is);
        _log.info("!!----------   "  + fastDI.getBean("b") + "   ---------------!!");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sev) {
        ;
    }
}